/**
 * Created by Administrator on 2015/6/2.
 */
var mysqlCli =require('mysql');
var logging = require('../../lib/logging.js');
var logger;
var DbOperator=function(){
   var self=this;
   logger = logging.getLogger('dboperator','abc',"DEBUG");
   self.settings=require("../../instance/abc/dbconfig");
   self.pool= mysqlCli.createPool({
       host:self.settings['host'],
       user:self.settings['user'],
       password:self.settings['password'],
       database:self.settings['database'],
       port:self.settings['port']
   });
}
DbOperator.prototype.executeSql=function(sql){
    this.pool.getConnection(function(err,conn){
        if(err) {
            logger.error("error sql:"+sql);
            logger.error(err);
        }else{
            conn.query(sql,function(err,rows){
                if(err) {
                    logger.error(err);
                }
                conn.release();
            });
        }
    });
}
DbOperator.prototype.executeSqlCallback=function(sql,cb){
    this.pool.getConnection(function(err,conn){
        if(err) {
            logger.error(err);
        }
        else{
            conn.query(sql,function(err,rows){
                if(err){
                    logger.error(err);
                }else{
                    cb(rows);
                }
                conn.release();
            });
        }
    });
}
DbOperator.prototype.closeConnection=function(){
    //pool.close();
};
module.exports = exports =new DbOperator();